package com.heimo.babyage.ui.framegrid;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;

import com.heimo.babyage.R;

public class FramePickerDialog extends Dialog {
	private OnFramePickedListener mlistener = null;

	public FramePickerDialog(Context ctx, OnFramePickedListener mlistener) {
		super(ctx);
		this.setTitle(ctx.getString(R.string.frameGridTitle));
		this.mlistener = mlistener;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.dialog_layout_frames);

		GridView gridViewFrames = (GridView) findViewById(R.id.gridViewFrames);
		final FramePickerAdapter adp = new FramePickerAdapter(getContext());
		gridViewFrames.setAdapter(adp);

		gridViewFrames.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// int frameID = adp.getImageIdByPos(position);
				mlistener.framePicked(position);
				FramePickerDialog.this.dismiss();
			}
		});
	}
}
